﻿using Minecraft.BLL;
using Minecraft.BLL.mysql;
using Minecraft.Config;
using Minecraft.Config.Csv.CsvCls;
using Minecraft.Config.Csv.CsvCom;
using Minecraft.Config.ipConst;
using Minecraft.Model;
using Minecraft.Model.ReqResp;
using SuperSocket.SocketBase.Command;
using SuperSocket.SocketBase.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Minecraft.ServerHall.Cmd
{
	public class TreasureboxListGenerate : CommandBase<MinecraftSession, StringRequestInfo>
	{
		public override string Name
		{
			get
			{
				return ProtocolHelper.GetProtocolStr(defCommand);
			}
		}
		private EnumCommand defCommand = EnumCommand.Treasurebox_TreasureboxListGenerate;
		public override void ExecuteCommand(MinecraftSession session, StringRequestInfo requestInfo)
		{
			var req = requestInfo.GetRequestObj<TreasureboxListGenerateReq>(session);
			if (req == null)
			{
				session.Send(defCommand, req, new BaseResp { RespLevel = RespLevelEnum.Error, Msg = $"错误1：（原因：请求实体为空）" });
				return;
			}
			if (!session.minecraftSessionInfo.IsLogin)
			{
				session.Send(defCommand, req, new BaseResp { RespLevel = RespLevelEnum.Error, Msg = $"错误1：（原因：未登录）" });
				return;
			}

			if (req.treasureBoxId.IsNullOrWhiteSpace())
			{
				session.Send(defCommand, req, new BaseResp { RespLevel = RespLevelEnum.Error, Msg = $"错误1：（原因：treasureBoxId参数为空）" });
				return;
			}
			if (req.point3 == null)
			{
				session.Send(defCommand, req, new BaseResp { RespLevel = RespLevelEnum.Error, Msg = $"错误1：（原因：req.point3 == null）" });
				return;
			}
			var treasureBoxInfo = session.minecraftSessionInfo.furnitureTreasureBoxList.FirstOrDefault(m => m.FurnitureId == req.treasureBoxId);
			if (treasureBoxInfo == null)
			{
				session.Send(defCommand, req, new BaseResp { RespLevel = RespLevelEnum.Error, Msg = $"错误1：（原因：treasureBoxInfo == null）" });
				return;
			}
			if (treasureBoxInfo.TreasureBox_IsGenerate_Convert)
			{
				session.Send(defCommand, req, new BaseResp { RespLevel = RespLevelEnum.Error, Msg = $"错误1：（原因：该宝箱已经生成过）" });
				return;
			}
			treasureBoxInfo.Point_X = req.point3.x;
			treasureBoxInfo.Point_Y = req.point3.y;
			treasureBoxInfo.Point_Z = req.point3.z;

			var resp = new TreasureboxListGenerateResp
			{

			};
			session.Send(defCommand, req, resp);
		}
	}
}
